<script lang="ts" setup>
import type { StateType } from './types';

import { computed } from 'vue';
import { useRoute } from 'vue-router';

import { Page,z } from '@vben/common-ui';
import { useTabs } from '@vben/hooks';

import { useTitle } from '@vueuse/core';
import {
  Card,
  message,
  
} from 'ant-design-vue';
import dayjs from 'dayjs';
import { storeToRefs } from 'pinia';

import { useVbenForm } from '#/adapter/form';
import { getpassword, savepassword } from '#/api/admin/resources';
import { usePreferencesStore } from '#/store';

const route = useRoute();

const { setTabTitle, closeCurrentTab } = useTabs();


const router = useRouter();

const routeMeta = router.currentRoute.value.meta;
const routeTitle = routeMeta.title.replace('管理', '');
const preferencesStore = usePreferencesStore();
const { title } = storeToRefs(preferencesStore);




const disabled = ref(true);
const activeKey = ref('1');
const state: StateType = reactive({
  form: {
    video: '',
    name: '',   
  },
  pageThemeFiles: [],
});

const [BasicForm, BasicFormApi] = useVbenForm({
  handleSubmit: onSubmit,
  resetButtonOptions: {
    show: false,
  },
  schema: [
    {
      component: 'Input',
      dependencies: {
        show: false,
        // 随意一个字段改变时，都会触发
        triggerFields: ['id'],
      },
      fieldName: 'id',
      label: 'ID',
    
    },
    {
      component: 'Input',
      defaultValue: '',
      dependencies: {
        trigger: (values) => {
        
          state.form.password = values.password;
        
        },
        // 随意一个字段改变时，都会触发
        triggerFields: [
          'id',

          'password'
        ],
      },
      componentProps: {
        placeholder: '请输入下载面（不能超过50个字符）',
      },
      fieldName: 'password',
      label: `${routeTitle}`,
       rules: z.string().max(50,'标题不能超过50字符'),
    },


       
  ],
});



async function onSubmit() {
    function showMsg(msg: string) {
      message.success(msg);
    
        
    }
    const values: any = state.form;

      const { msg } = await savepassword(values);
      showMsg(msg);
}
async function onGetPage() {
    const res = await getpassword();
    state.form.password = res.password;
    BasicFormApi.setValues({ ...state.form});
}

onMounted(async () => {
    await onGetPage();
  
});




</script>

<template>
  <Page>
    <Card :title="`${routeTitle}`">
      <BasicForm/>
    </Card>
  </Page>
</template>
